package part21;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author wcj
 * @Date 2021/6/7 16:45
 * @Version 1.0
 */
public class Part215 {
}

class SleepingTask extends LiftOff {
    @Override
    public void run() {
        try {
            while (countDown-- > 0) {
                System.out.println(status());
                TimeUnit.MILLISECONDS.sleep(100);
            }
        } catch (InterruptedException e) {
            System.err.println("Interrupt");
        }
    }

    /**
     * Sleep：让线程进入到睡眠状态，但是并不会让出CPU资源或者锁资源
     * Yield：让线程让出CPU资源或者锁资源
     *
     * @param args
     */
    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++) {
            exec.execute(new SleepingTask());
        }
        exec.shutdown();
    }
}
